package snapex.expense.mapper;

import static org.mybatis.dynamic.sql.SqlBuilder.*;
import static snapex.expense.mapper.CurrencyRateDynamicSqlSupport.*;

import java.util.List;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.SqlBuilder;
import org.mybatis.dynamic.sql.delete.DeleteDSL;
import org.mybatis.dynamic.sql.delete.MyBatis3DeleteModelAdapter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.render.RenderingStrategy;
import org.mybatis.dynamic.sql.select.MyBatis3SelectModelAdapter;
import org.mybatis.dynamic.sql.select.QueryExpressionDSL;
import org.mybatis.dynamic.sql.select.SelectDSL;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.MyBatis3UpdateModelAdapter;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import snapex.core.model.CurrencyRate;

@Mapper
public interface HtcCurrencyRateMapper {
    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    int insert(InsertStatementProvider<CurrencyRate> insertStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("CurrencyRateResult")
    CurrencyRate selectOne(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="CurrencyRateResult", value = {
        @Result(column="currency", property="currency", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="rate_month", property="rateMonth", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="rate", property="rate", jdbcType=JdbcType.DECIMAL)
    })
    List<CurrencyRate> selectMany(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default QueryExpressionDSL<MyBatis3SelectModelAdapter<Long>> countByExample() {
        return SelectDSL.selectWithMapper(this::count, SqlBuilder.count())
                .from(currencyRate);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default DeleteDSL<MyBatis3DeleteModelAdapter<Integer>> deleteByExample() {
        return DeleteDSL.deleteFromWithMapper(this::delete, currencyRate);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int deleteByPrimaryKey(String currency_, String rateMonth_) {
        return DeleteDSL.deleteFromWithMapper(this::delete, currencyRate)
                .where(currency, isEqualTo(currency_))
                .and(rateMonth, isEqualTo(rateMonth_))
                .build()
                .execute();
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insert(CurrencyRate record) {
        return insert(SqlBuilder.insert(record)
                .into(currencyRate)
                .map(currency).toProperty("currency")
                .map(rateMonth).toProperty("rateMonth")
                .map(rate).toProperty("rate")
                .build()
                .render(RenderingStrategy.MYBATIS3));
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insertSelective(CurrencyRate record) {
        return insert(SqlBuilder.insert(record)
                .into(currencyRate)
                .map(currency).toPropertyWhenPresent("currency", record::getCurrency)
                .map(rateMonth).toPropertyWhenPresent("rateMonth", record::getRateMonth)
                .map(rate).toPropertyWhenPresent("rate", record::getRate)
                .build()
                .render(RenderingStrategy.MYBATIS3));
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default QueryExpressionDSL<MyBatis3SelectModelAdapter<List<CurrencyRate>>> selectByExample() {
        return SelectDSL.selectWithMapper(this::selectMany, currency, rateMonth, rate)
                .from(currencyRate);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default QueryExpressionDSL<MyBatis3SelectModelAdapter<List<CurrencyRate>>> selectDistinctByExample() {
        return SelectDSL.selectDistinctWithMapper(this::selectMany, currency, rateMonth, rate)
                .from(currencyRate);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default CurrencyRate selectByPrimaryKey(String currency_, String rateMonth_) {
        return SelectDSL.selectWithMapper(this::selectOne, currency, rateMonth, rate)
                .from(currencyRate)
                .where(currency, isEqualTo(currency_))
                .and(rateMonth, isEqualTo(rateMonth_))
                .build()
                .execute();
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default UpdateDSL<MyBatis3UpdateModelAdapter<Integer>> updateByExample(CurrencyRate record) {
        return UpdateDSL.updateWithMapper(this::update, currencyRate)
                .set(currency).equalTo(record::getCurrency)
                .set(rateMonth).equalTo(record::getRateMonth)
                .set(rate).equalTo(record::getRate);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default UpdateDSL<MyBatis3UpdateModelAdapter<Integer>> updateByExampleSelective(CurrencyRate record) {
        return UpdateDSL.updateWithMapper(this::update, currencyRate)
                .set(currency).equalToWhenPresent(record::getCurrency)
                .set(rateMonth).equalToWhenPresent(record::getRateMonth)
                .set(rate).equalToWhenPresent(record::getRate);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKey(CurrencyRate record) {
        return UpdateDSL.updateWithMapper(this::update, currencyRate)
                .set(rate).equalTo(record::getRate)
                .where(currency, isEqualTo(record::getCurrency))
                .and(rateMonth, isEqualTo(record::getRateMonth))
                .build()
                .execute();
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKeySelective(CurrencyRate record) {
        return UpdateDSL.updateWithMapper(this::update, currencyRate)
                .set(rate).equalToWhenPresent(record::getRate)
                .where(currency, isEqualTo(record::getCurrency))
                .and(rateMonth, isEqualTo(record::getRateMonth))
                .build()
                .execute();
    }
}